// pages/sp_list/sp_list.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sys_h: wx.getSystemInfoSync().windowHeight, // 设备屏幕高度
    categorys: [
      {
        category: "为您推荐",
        content: [

        ]
      },
      {
        category: "数码",
        content: [
          {
            cont: [
              { name: "衣服", img: "http:////img.alicdn.com/tfs/TB1JjmnqkOWBuNjSsppXXXPgpXa-100-100.jpg_250x225Q50s50.jpg_.webp" },
              { name: "衣服", img: "http:////img.alicdn.com/tfs/TB1JjmnqkOWBuNjSsppXXXPgpXa-100-100.jpg_250x225Q50s50.jpg_.webp" },
              { name: "衣服", img: "http:////img.alicdn.com/tfs/TB1JjmnqkOWBuNjSsppXXXPgpXa-100-100.jpg_250x225Q50s50.jpg_.webp" },
              { name: "衣服", img: "http:////img.alicdn.com/tfs/TB1JjmnqkOWBuNjSsppXXXPgpXa-100-100.jpg_250x225Q50s50.jpg_.webp" },
              { name: "衣服", img: "http:////img.alicdn.com/tfs/TB1JjmnqkOWBuNjSsppXXXPgpXa-100-100.jpg_250x225Q50s50.jpg_.webp" },
              { name: "衣服", img: "http:////img.alicdn.com/tfs/TB1JjmnqkOWBuNjSsppXXXPgpXa-100-100.jpg_250x225Q50s50.jpg_.webp" },
              
            ]
          }
        ]
      },
      {
        category: "男装",
        content: []
      },
      {
        category: "女装",
        content: []
      },
      {
        category: "食品",
        content: []
      },
      {
        category: "家居",
        content: []
      },
      {
        category: "生鲜",
        content: []
      },
      {
        category: "饰品",
        content: []
      },
      {
        category: "母婴",
        content: []
      },
      {
        category: "手机",
        content: []
      },
      {
        category: "美妆",
        content: []
      },
      {
        category: "洗护",
        content: []
      },
      {
        category: "箱包",
        content: []
      },
      {
        category: "运动",
        content: []
      },
      {
        category: "户外",
        content: []
      },
      {
        category: "居家百货",
        content: []
      },
      {
        category: "鲜花宠物",
        content: []
      },
      {
        category: "食品",
        content: []
      },
      {
        category: "生鲜",
        content: []
      },
      {
        category: "汽车摩托",
        content: []
      },
      {
        category: "医药",
        content: []
      },
      {
        category: "图书",
        content: []
      },
      {
        category: "通信",
        content: []
      },
      {
        category: "洗护",
        content: []
      },
      {
        category: "乐器",
        content: []
      }
    ],
    current: 0, // 当前分类

    scroll_dire: 'down',  // 滚动方向，默认向下滚动
    showTop: true,
    showBtm: false,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
  
    var that= this;
    that.shop_list()
    if(options.current != null ){
      that.setData({
        current:Number(options.current)+1,
        showTop:false
      })
    }
    

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

/*商品列表*/
  scroll(ev) {
    ev.detail.deltaY > 0 ? this.setData({ scroll_dire: 'up' }) : this.setData({ scroll_dire: 'down' });
    const query = wx.createSelectorQuery();
    query.select('.selected').boundingClientRect();
    query.selectViewport().scrollOffset();
    query.exec((res) => {
      let top = res[0].top, // 元素距离顶部的距离;
        h = res[0].height; // 元素的高度
      // if (top <= 0 && this.data.scroll_dire == 'down') {
      //   this.setData({ showTop: true, showBtm: false });
      //   console.log(1)
      // } else if (top < 0 && this.data.scroll_dire == 'up') {
      //   this.setData({ showTop: true, showBtm: false })
      //   console.log(2)
      // } else if ((top + h) >= 603 && this.data.scroll_dire == 'up') {
      //   this.setData({ showTop: false, showBtm: true })
      //   console.log(3)
      // } 
      // else if ((top + h) >= 603 && this.data.scroll_dire == 'down') {
      //   this.setData({ showTop: false, showBtm: true })
      //   console.log(4)
      // }
      // else {
      //   console.log(5)
      //   this.setData({ showTop: false, showBtm: false })
      // }
      if (top <= 0) {
        this.setData({ showTop: true, showBtm: false });
      } else if ((top + h) >= 603) {
        this.setData({ showTop: false, showBtm: true })
      } else {
        this.setData({ showTop: false, showBtm: false })
      }
    })
  },

  // 选择当前分类
  selCate(ev) {

    let ind = Number(ev.currentTarget.dataset.index);
    let id = ev.currentTarget.dataset.id;
    if (!Number.isNaN(ind)) { 
      this.setData({ current: ind, showTop: false, showBtm: false }) 
    }
    //this.shop_list(id);
  },
  //加载显示分类
  shop_list(id){
    var that = this;
    app.wxRequest('POST','/Home/Goods/shop_list',{'id':id},function(res){
      if(res.data.code == 0){
        that.setData({
          categorys:res.data.data,
        })
        console.log(that.data.categorys)
      }
    })
  }


})